@isTest
private class AboardPriceListControllerTest {
    static testMethod void testMethod1() {
         Account acc = TestUtils.createAccount();
        acc.Name = '客户A';
        acc.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('DealerAbroad','Account');
        insert acc;


        Product__c p1 = TestUtils.createProduct();
        p1.Category0__c = '试剂';
        p1.PriceCompany__c = 'MKSW';
        p1.ProductName__c = '测试试剂';
        p1.NCCode__c = '000001';
        p1.Brand__c = 'maccura';

       // p1.Overseasproducts__c = true;
        p1.Category3__c = '试剂';
        p1.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('NCProduct', 'Product__c');
        insert p1;


         // 价格
        Price__c price = TestUtils.createPrice();
        price.Product__c = p1.Id;
        price.Company__c ='迈克生物股份有限公司' ;
        price.InstCost__c = 10.0;
        price.MarketPriceUSD__c = 10; 
        //price.Province__c = [Select  PriceProvince__c from User where Id=:UserInfo.getUserId()].PriceProvince__c;

        insert price; 

        //价目表
        PriceList__c pl = new PriceList__c();
        pl.Product__c = p1.Id;
        pl.SalesCode__c = '01';
        pl.Price__c = 100;
        pl.Account__c = acc.Id;
        pl.ApplicableCustomers__c = acc.Id;
        pl.Company__c = '迈克生物股份有限公司';

        insert pl;

        AboardPriceListController.matchProduct(new List<String>{'000001'}, acc.Id , '迈克生物股份有限公司',null);
            //新建
        PageReference page = new PageReference('/apex/AboardPriceList?id=' + acc.Id );
        System.Test.setCurrentPage(page);
        AboardPriceListController apc = new AboardPriceListController();
        apc.init();
        Map<String,String> searchMap = new Map<String,String>();
        searchMap.put('ProductName__c','测试');

        apc.searchJson = EncodingUtil.urlEncode(JSON.serialize(searchMap),'UTF-8');
        apc.search();

        System.debug([select Id ,Category3__c,Overseasproducts__c,Brand__c from Product__c where Id=:p1.Id ]);

        apc.searchPriceList();

         Map<String,Object>saveMap = new Map<String,Object>();

        Map<String ,Object> baseMap = new Map<String,Object>();
        baseMap.put('Reason__c', '1');
       
        saveMap.put('base',baseMap);

         List<Object> details = (List<Object>)JSON.deserializeUntyped( EncodingUtil.urlDecode(apc.dataJson, 'UTF-8'));
        Map<String,Object> d = (Map<String,Object> ) details.get(0);
        d.put('marketprice', 10);
        saveMap.put('detail',details);
        System.debug('QuoteAboardControllerTest==>'+saveMap);
         apc.saveJson = EncodingUtil.urlEncode(JSON.serialize(saveMap),'UTF-8');
        apc.save();
        System.debug('QuoteAboardControllerTest==>'+apc.msg);

        AdjustPrice__c ap = [select Id from AdjustPrice__c where Account__c =: acc.Id];

             //编辑 
        PageReference page1 = new PageReference('/apex/AboardPriceList?id=' + ap.Id );
        System.Test.setCurrentPage(page1);
        AboardPriceListController apc1 = new AboardPriceListController();
        apc1.init();



    }
}